package aseCrypto;

import java.math.BigInteger;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author haui
 */
public class AseIntegerTest_Basic_Functionality_All_Has_To_Work {

    AseInteger my160;
    AseInteger my20;
    AseInteger myBig1;

    public AseIntegerTest_Basic_Functionality_All_Has_To_Work() {
    }

    @BeforeClass
    public static void setUpClass() {
    }

    @AfterClass
    public static void tearDownClass() {
    }

    @Before
    public void setUp() {

        my160 = new AseInteger("160");
        my20 = new AseInteger("20");
        myBig1 = new AseInteger("1000000");

    }

    @After
    public void tearDown() {
    }

    /**
     * Test of add method, of class AseInteger.
     */
    @Test
    public void testAdd() {

        AseInteger arg0 = new AseInteger("152");
        AseInteger instance = new AseInteger("152");
        AseInteger expResult = new AseInteger("304");
        AseInteger result = instance.add(arg0);

        assertEquals(expResult.toString(), result.toString());


        arg0 = new AseInteger("152000000");
        instance = new AseInteger("152000000");
        expResult = new AseInteger("304000000");
        result = instance.add(arg0);

        assertEquals(expResult.toString(), result.toString());


        arg0 = new AseInteger("152000000");
        instance = new AseInteger("1");
        expResult = new AseInteger("152000001");
        result = instance.add(arg0);

        assertEquals(expResult.toString(), result.toString());


    }

    /**
     * Test of compareTo method, of class AseInteger.
     */
    @Test
    public void testCompareTo() {

        assertEquals(1, 1);

        assertEquals(0, new AseInteger("1").compareTo(new AseInteger("1")));

    }

    /**
     * Test of divide method, of class AseInteger.
     */
    @Test
    public void testDivide() {

        AseInteger arg0 = new AseInteger("30");
        AseInteger instance = new AseInteger("600");
        AseInteger expResult = new AseInteger("20");
        AseInteger result = instance.divide(arg0);
        assertEquals(expResult.toString(), result.toString());

    }

    /**
     * Test of divideAndRemainder method, of class AseInteger.
     */
    @Test
    public void testDivideAndRemainder() {

        AseInteger biggerNumber = new AseInteger("160001");

        AseInteger[] divisionResult = biggerNumber.divideAndRemainder(new AseInteger("4"));

        assertEquals(divisionResult[0].toString(), "40000");
        assertEquals(divisionResult[1].toString(), "1");

    }

    /**
     * Test of multiply method, of class AseInteger.
     */
    @Test
    public void testMultiply() {

        AseInteger arg0 = my160;
        AseInteger instance = my20;
        AseInteger expResult = new AseInteger("3200");
        AseInteger result = instance.multiply(arg0);

        assertEquals(expResult.toString(), result.toString());

        arg0 = my160;
        instance = myBig1;
        expResult = new AseInteger("160000000");
        result = instance.multiply(arg0);

        assertEquals(expResult.toString(), result.toString());

    }

    /**
     * Test of subtract method, of class AseInteger.
     */
    @Test
    public void testSubtract() {

        AseInteger arg0 = my20;
        AseInteger instance = my160;
        AseInteger expResult = new AseInteger("140");
        AseInteger result = instance.subtract(arg0);
        assertEquals(expResult.toString(), result.toString());

    }



    /**
     * Test of pow method, of class AseInteger.
     */
    @Test
    public void testPow() {

        int exponent = 4;
        AseInteger instance = my160;
        AseInteger expResult = new AseInteger("655360000");
        AseInteger result = instance.pow(exponent);

    }


    /**
     * Test of toString method, of class AseInteger.
     */
    @Test
    public void testToString() {

        AseInteger instance = new AseInteger("152");

        String expResult = "152";

        String result = instance.toString();

        assertEquals(expResult, result);


        instance = new AseInteger(BigInteger.valueOf(154));

        expResult = "154";

        result = instance.toString();

        assertEquals(expResult, result);


        instance = new AseInteger(BigInteger.ONE);

        expResult = "1";

        result = instance.toString();

        assertEquals(expResult, result);


        instance = AseInteger.ZERO;

        expResult = "0";

        result = instance.toString();

        assertEquals(expResult, result);

        instance = AseInteger.TEN;

        expResult = "10";

        result = instance.toString();

        assertEquals(expResult, result);

    }

    /**
     * Test of getGcd method, of class AseInteger.
     */
    @Test
    public void testGetGcd() {

        AseInteger IntegerToGetGcdWith = new AseInteger("56");

        AseInteger instanceToComputeWith = new AseInteger("123456");

        AseInteger expResult = new AseInteger("8");

        AseInteger result = instanceToComputeWith.getGcd(IntegerToGetGcdWith);

        //System.out.println("Haui: *" + result + "*");
        //System.out.println("Haui: *" + expResult + "*");

        assertEquals(expResult.toString(), result.toString());
        assertTrue(expResult.compareTo(result) == 0);

        //Hier stimmt etwas in Basisklasse nicht
        //assertEquals(expResult, result);


    }


}
